package com.jzo2o.market.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 优惠券类型枚举类
 * @author JIAN
 */
@Getter
@AllArgsConstructor
public enum CouponTypeEnum {
    AMOUNT_DISCOUNT(1, "满减"),
    RATE_DISCOUNT(2, "打折");

    @EnumValue
    @JsonValue
    private int type;
    private String name;

    public boolean equals(Integer type) {
        return type != null && type.equals(this.type);
    }

    public static CouponTypeEnum typeOf(Integer type) {
        if (type == null) {
            return null;
        }

        for (CouponTypeEnum couponTypeEnum : CouponTypeEnum.values()) {
            if (couponTypeEnum.getType() == type) {
                return couponTypeEnum;
            }
        }

        // not found
        return null;
    }
}